import { Component } from 'react';

import { Toast, Button, Group, TextareaField} from 'saltui';
import DB from '../../../app/db';
import './PageHome.less';
const {
	Count
} = TextareaField;
export default class PageHome extends Component {

 constructor(props) {
    super(props);

    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    
    let userArray = this.props.params.userArray;
    let meetingId = this.props.params.meetingId;
    this.state = {
      meetingId:meetingId,
      userArray:userArray,
      context:'',
    };

    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
          title : "发送提醒",//控制标题文本，空字符串表示显示默认文本
          onSuccess : function(result) {},
          onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
          title: {
              text: "发送提醒",
              icon: '',
              actionmenu: {}
          },
      });
    }

    /*let t = this;
    let userId = document.getElementById("userHiddenId").value;
    var isHelpNew = 1;
    dd.util.domainStorage.getItem({ //帮助按钮
       name:'meeting_helpNew_'+userId , // 存储信息的key值
       onSuccess : function(info) {
            var helpNew = info.value;
            if( typeof(helpNew) == 'undefined' || helpNew == '' ){
              isHelpNew = 2;
            }
            //初始化按钮
            t.initButton(isHelpNew);
       },
       onFail : function(err) {
            //alert(JSON.stringify(err));
       }
    });*/
  }

  //初始化按钮
  initButton(isHelpNew){
    //设置帮助
    /*dd.biz.navigation.setIcon({
        showIcon : true,//是否显示icon
        iconIndex : isHelpNew,//显示的iconIndex,如上图
        onSuccess : function(result) {
            location.hash='help/help_index';
        },
        onFail : function(err) {
        //jsapi调用失败将会回调此函数
        }
    });*/
  }

  
  //文本框输入
  handleTextChange(field, newValue, size) {
    if (newValue.length <= size) {
      this.setState({
        [field]: newValue,
      });
    }
  }
  
  submit(){
    if (this.state.context.trim()=='') {
      Toast.show({
              type: 'error',
              content: '请填写提醒内容',
              onHide: function () {
              }
          });
      return;
    }

    let param = {
      applyRecordId: this.state.meetingId,
      userArrays:this.state.userArray,
      context:this.state.context
    }

    DB.SomeModuleAPI.sendMeetingRemind(param).then((content) => {
          Toast.show({
          type: 'success',
              content: '发送成功'
           });
          //返回至列表页面
          setTimeout(function(){
            backPage();
          },1000);
        }).catch((error) => {          
            if(typeof(error.errorMsg) == 'undefined'){
              Toast.show({
              type: 'error',
              content: '发送出错'
               });
            }else{
              Toast.show({
              type: 'error',
              content: error.errorMsg
               });
            }
        });

  }

  cancel(){
    history.back();
  }

  render() {
    let t = this;
    return (
      <div>
          <div>
            <Group.List >
              <TextareaField
                required
                label="提醒内容" minRows={6} maxRows={10}
                placeholder="请输入提醒内容"
                value={t.state.context}
                onChange={(value) => { t.handleTextChange('context', value, 200); }}>
                <Count total={200} length={t.state.context.length} />
              </TextareaField>
            </Group.List>
          </div>

          <div >
              <Button.Group >
                  <Button type="primary" display="inline" onClick={this.submit.bind(this)}>发送</Button>
                  <Button type="secondary" display="inline" onClick={this.cancel.bind(this)}>取消</Button>             
              </Button.Group>
          </div>
        
    </div>);
  }
}


